<?php
defined('_JEXEC') or die('Restricted access'); 
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

	
	$productId = WrdHelper::getProductVoucher(); 
	$arr = array();
	for($i=0;$i < count($productId);$i++){
		$arr[] = $productId[$i]->id;
	}
	$list = implode(',',$arr);
?>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<link href="<?php echo JURI::root();?>administrator/components/com_wrd/assets/css/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script src="<?php echo JURI::root();?>administrator/components/com_wrd/assets/js/jquery-ui-1.9.2.custom.js"></script>

<script src="<?php echo JURI::root();?>administrator/components/com_wrd/assets/js/jquery.bpopup.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::root();?>administrator/components/com_wrd/assets/js/json_encode.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root();?>/js/multiselect/jquery-ui.css" />

<link type="text/css" href="<?php echo JURI::root();?>/css/buttons.css" rel="stylesheet" />

<script type="text/javascript">
	
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'redirect_to_profile' || pressbutton == 'products_page') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save_new_redemption') {
			if (document.adminForm.cat_id.value == 0) {
				alert( 'Please select a category !' );
				document.adminForm.cat_id.focus();
				return false;
			}
			if (document.adminForm.quantity.value == '') {
				alert( 'Must have quantity !' );
				document.adminForm.quantity.focus();
				return false;
			}
			if (isNaN(document.adminForm.quantity.value)) {
				alert( 'Quantity have to a number !' );
				document.adminForm.quantity.focus();
				return false;
		    }
			submitform( pressbutton );
		}
	}
	
	<?php echo $this->lists['scriptCategoryProduct']; ?>
    
    jQuery.noConflict();
    function initProductList(catIds)
    {
        jQuery("#product_id").html("");
        
        if(catIds != null && catIds != "") {
            for(var index=0; index<catIds.length; index++) {
                var products = categories[catIds[index]];
                if(jQuery(products).length > 0)
                {   
                    for(var i=0; i<products.length; i++) {
                        jQuery("#product_id").html(jQuery("#product_id").html() +"<option value="+products[i][0]+">"+products[i][1]+"</option>");
                    }
                }
            }
        }
        else {
            for(var index=0; index<categories.length; index++) {
                var products = categories[index];
                if(jQuery(products).length > 0)
                {   
                    for(var i=0; i<products.length; i++) {
                        jQuery("#product_id").html(jQuery("#product_id").html() +"<option value="+products[i][0]+">"+products[i][1]+"</option>");
                    }
                }
            }
        }
        var htmlProduct = jQuery("#product_id").html();
        jQuery("#redemption_quantity tr").each(function(index){
            jQuery(this).find("select").html(htmlProduct);
        });
    }
	
</script>
<script type="text/javascript">
	//<![CDATA[
		jQuery.noConflict();
	    jQuery(document).ready(function(){
			initProductList(jQuery("#cat_id").val());
            /******* Category List *******/
            jQuery("#cat_id").change(function(){                
                initProductList(jQuery(this).val());
            });
            /******* Quantity Input *******/
	        jQuery("#quantity").change(function(){
	        	var cat_id = jQuery("#cat_id").val() ;
	        	var product_id = jQuery("#product_id").val() ;
	        	var p_o_u = jQuery("#p_o_u").val() ;
		        var quantity = jQuery("#quantity").val() ;
		        var p_quantity = jQuery("#p_quantity").val() ;
		        var pointx = jQuery("#pointx").val() ;
		        var cash = jQuery("#cash").val() ;
				if(parseInt(cat_id) == '' || parseInt(cat_id) == 0){
					alert('Please choose a category');
				}else if(parseInt(product_id) == '' || parseInt(product_id) == 0){
					alert('Please choose a product') ;
				}else{
					if(parseInt(quantity) <= 0 ){
						alert('Quantity is not correct') ;
					}else{
						if(parseInt(quantity) > parseInt(p_quantity )){
							alert('Quantity must be less than (or equal to) '+parseInt(p_quantity));
						}else{
							var points_cost = quantity * pointx ;
							if(parseInt(points_cost) > parseInt(p_o_u)){
								alert('Not enought points for this exchange') ;
							}
						}
					}
				}
	        });
            
            /******* Style Link *******/
            jQuery(".special-link").hover(
                function(){
                    jQuery(this).addClass("ui-state-hover");
                },
                function(){
                    jQuery(this).removeClass("ui-state-hover");
                }
            );
            
            /******* Update Transaction *******/
            jQuery("#update_transaction").click(function(){
                var flag = true;
                if(jQuery("#product_id").val() == null || jQuery("#product_id").val() == "")
                {
                    alert("Please select a category!");
                    return false;
                }
                jQuery("#redemption_quantity tr.active").find("input.quantity").each(function(){
                    if(jQuery(this).val() == ""){
                        flag = false;
                    }
                });
                
                /*********** Update Transaction ***********/
                if(flag == false)
                {
                    alert("Please fill all quantiy!");
                }
                else {
                    var productList = new Array();
                    
                    jQuery("#redemption_quantity tr.active:gt(0)").each(function(){
                        var currentProductId = jQuery(this).find("select").first().val();
                        var flag = true;
                        for(var i=0; i<productList.length; i++){
                            if(productList[i].id == currentProductId){
                                flag = false;
                            }
                        }
                        if(flag == true) {
                            productItem = ({
                               id: currentProductId,
                               quantity: jQuery(this).find("input[type=text]").first().val() 
                            });
                            productList.push(productItem);
                        }
                        
                    });
                    
                    jQuery("#loadingImg").show();
                    totalPoint = autoFilePointForTransaction();
                    updateProductId();
                    var queryString = 'uid=<?php echo intval($_GET['uid']) ?>' + "&totalPoint="+totalPoint;
                    queryString += "&productList=" + json_encode(productList);
                    
                    jQuery.ajax({
                        url: "index.php?option=com_wrd&controller=profile&layout=pointlist",
                        type: "POST",
                        data: queryString,
                        success: function (res) {
                            jQuery('#update_transaction_panel_content').html(res);
                            jQuery('#update_transaction_panel').slideDown("slow");
                            jQuery("#loadingImg").hide();
                        }
                    });   
                }
            });
            
			/******* Redemption Quantity *******/
            showProductQuantity(jQuery("#product_quantity").val());
			
			
			jQuery("#product_quantity").change(function(){
				showProductQuantity(jQuery(this).val());
				var to = jQuery(this).val();
				setCookie("k",to,365);
				//alert(k);
				//alert(to);
				jQuery(function() {
						jQuery('.datepicker').datepicker( {
							onSelect: function(date) {
								var k = parseInt(getCookie("k"));
								var j = jQuery(this).attr('rel');
								for(i = j; i <= k; i++){
									jQuery("#datepicker"+i).val(date);
									continue;	
								}
							},
							showOn: "button",
							buttonImage: "<?php echo JURI::root();?>administrator/components/com_wrd/assets/images/calendar24x24.png",
							buttonImageOnly: true,
							dateFormat: "d-m-yy",
						});
						
				});
				
            });
			
			jQuery(function() {
				jQuery('#datepicker1').datepicker( {
					
					onSelect: function(date) {
						var j = jQuery(this).attr('rel');
						cur = jQuery("#product_quantity").val();

							for(i = j; i <= cur; i++){
							
								jQuery("#datepicker"+i).val(date);	
							} 
						
					},
					
					showOn: "button",
					buttonImage: "<?php echo JURI::root();?>administrator/components/com_wrd/assets/images/calendar24x24.png",
					buttonImageOnly: true,
					dateFormat: "d-m-yy",
				});
			});
			
			//cookie
			function getCookie(c_name)
			{
				var c_value = document.cookie;
				
				var c_start = c_value.indexOf(" " + c_name + "=");
				
				if (c_start == -1)
				{
					c_start = c_value.indexOf(c_name + "=");
				}
				
				if (c_start == -1)
				{
					c_value = null;
				}
				
				else
				{
					c_start = c_value.indexOf("=", c_start) + 1;
						
					var c_end = c_value.indexOf(";", c_start);
					
					if (c_end == -1)
					{
						c_end = c_value.length;
					}
						c_value = unescape(c_value.substring(c_start,c_end));
				}
				
				return c_value;
			}
			function setCookie(c_name,value,exdays)
			{
				var exdate=new Date();
				exdate.setDate(exdate.getDate() + exdays);
				var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
				document.cookie = c_name + "=" + c_value;
			}
			//end cookie
			
            checkVoucher(jQuery("#product_quantity").val());
            jQuery("#product_quantity").change(function(){
                checkVoucher(jQuery(this).val());
            });
			
            // Dialog
            jQuery('#dialog').dialog({
                autoOpen: false,
                width: 500,
                height: 380,
                open: function(){
                    jQuery(".dialog-content").html("");
                    var queryString = 'id='+jQuery("#current-product-id").val();
                    jQuery.ajax({
                        type: "POST",
                        url: "<?php echo JURI::root();?>administrator/index.php?option=com_wrd&controller=profile&layout=viewproductdetails",
                        data: queryString,
                    }).success(function( html ) {
                        jQuery(".dialog-content").html(html);
                        jQuery(this).dialog("open");
                    });
                    
                },
                buttons: {
                    "Ok": function() {
                        jQuery(this).dialog("close");
                    }
                }
            });
            jQuery('.view-product-detail').click(function(index){
                
				jQuery("#current-product-id").val(jQuery(this).prev("select").val());
                jQuery('#dialog').dialog('open');
                return false;               
            });
            
            //console.log(productList.length);
			function checkVoucher(currentDisplay){
				var list = '<?php echo $list;?>';
				list = list.split(",");
				//alert(currentDisplay);
				for(i=1;i<=currentDisplay;i++){
					var a = jQuery("select[name='product_name_list[product_list_"+i+"]']").val();
					if(list.indexOf(a) != -1){
						jQuery(".v").show();
						jQuery("div.v"+i).html('<input type="text" name="product_list_'+i+'_voucher" class="voucherlist" onchange="updateVoucherList('+i+')" rel="'+i+'" id="product_list_'+i+'_voucher" style="width:120px;" />');
						
						jQuery("div.e"+i).show();
						
						jQuery("td.a").css("width","42%");
						jQuery("#product_list_"+i).val(1).attr('readonly','readonly');
						
					}
					
					else if(list.indexOf(a) == -1){
						jQuery("div.v"+i).html('');
						jQuery("div.e"+i).show();
						jQuery("#product_list_"+i).val('').removeAttr('readonly');
					}
					
					jQuery("select[name='product_name_list[product_list_"+i+"]']").change(function(){
						//jQuery("#product_list_"+i+"_np").val() = jQuery(this).find("option:selected").text();
						checkVoucher(currentDisplay);
					});
				}
			}
		//var id = jQuery("select[name='product_name_list[product_list_1]']").val();

		jQuery("select.product_list").change(function(){
		
			var i = jQuery(this).attr("rel");		
			jQuery.ajax({
			
				url: "index.php?option=com_wrd&controller=profile&task=getPointCashProduct",
				type: "POST",
				data: 'id='+jQuery(this).val(),
				success: function (res) {
					if(res) {
						arr = res.split(";");
						//alert(i);alert(arr[0]);
						jQuery("#p"+i).html(arr[0]+" point");
						jQuery("#pc"+i).html(arr[1]+" Point<br/>"+arr[2]+" Cash");
					}
					else {
						alert(123456);
					}
				}
				
			});
			
		});		
});
		
        function updateProductId() {
            jQuery("#redemption_quantity tbody tr.active").each(function(){
                jQuery(this).find("input[type=hidden]").first().val(jQuery(this).find("select").first().val());
            });
			jQuery("#redemption_quantity tbody tr.t").each(function(){
                jQuery(this).find("input[type=hidden]").first().val("");
            });
        }
        
        function autoFilePointForTransaction(){
            var totalPoint = 0;
            jQuery("#redemption_quantity tbody tr.active").each(function(){
                
                quantity = jQuery(this).find("input[type=text]").first().val();
                typeRedemption = jQuery(this).find("input[type=radio]:checked").val();
                productIndex = jQuery(this).find("select").first().val();
                if(typeRedemption == 1) {
                    totalPoint += (parseInt(productList[productIndex][0])*parseInt(quantity));
                }
                else {
                    totalPoint += (parseInt(productList[productIndex][1])*parseInt(quantity));
                }
            });
            
            return totalPoint;
        }
        function showProductQuantity(currentDisplay)
        {
			//alert(currentDisplay);
			var htmlProduct = jQuery("#product_id").html();
			//alert(currentDisplay);
            jQuery("#redemption_quantity tr").each(function(index){
                if(index <= currentDisplay){
                    jQuery(this).attr("class", "active");
                    jQuery(this).find("select").html(htmlProduct);
                    jQuery(this).show();
                }
                else {
                    jQuery(this).attr("class", "t");
                    jQuery(this).hide();
                }
            }); 
			
		 	//***************
			//m = 0;
			for(i=1;i<= parseInt(currentDisplay)+1;i++){
				
				var id = jQuery("#product_list"+i).val();
				callAjaxTest(id,i,parseInt(currentDisplay));
				//m++;
				
			}
			//console.log(m);
			//*******
        }
		
		function callAjaxTest(id,i,cur){
			if(cur>5){
			jQuery(function(){
				//jQuery("#aaa").bind("click",function(e){
					// e.preventDefault();
					jQuery('#element_to_pop_up').bPopup({
						//easing: 'easeOutBack', //uses jQuery easing plugin
						speed: 450,
						transition: 'slideDown',
						modalClose: false
					});
				//});
			});
			}
			jQuery.ajax({
			
					url: "index.php?option=com_wrd&controller=profile&task=getPointCashProduct",
					type: "POST",
					data: 'id='+id,
					success: function (res) {
						if(res) {
							arr = res.split(";");
							//alert(i);alert(arr[0]);
							//alert(i);
							
							jQuery("#p"+(i-1)).html(arr[0]+" point<br/>");
							jQuery("#pc"+(i-1)).html(arr[1]+" Point<br/>"+arr[2]+" Cash");
							if(i==cur&&cur>5){
								jQuery('#element_to_pop_up').bPopup().close();
							}
						}
						else {
							alert(123456);
						}
						
					}
				
				});
		}
		
		function updateVoucherList(rel){
			var rel = parseInt(rel);			
			var indexval = '';
			var preval = jQuery('#product_list_'+rel+'_voucher').val()
			var quality = jQuery('#product_quantity').val();

			for(var index=1; index<=quality; index++) {
               var indexrel = parseInt(''+jQuery('#product_list_'+index+'_voucher').attr('rel'));
               if(indexrel > rel){
					indexval = countingSequense(indexval == '' ? preval : indexval);
					jQuery('#product_list_'+index+'_voucher').val(indexval);
				}
            }
		}
		
		function countingSequense(input){
			var output = '';
			var arr_out = input.split("");
			var arr_len = arr_out.length-1;
			var owe = 1;
			//console.log(arr_out)
			//last one is char
			if(isNaN(arr_out[arr_len])){
				return output;
			}
			
			for(var i = arr_len; i >=0; i--) {
				
				if(!isNaN(arr_out[i])){
					
					arr_out[i]=parseInt(arr_out[i])+owe;
					owe = 0;
					if(arr_out[i] == 10){
						if(!isNaN(arr_out[i-1])){
							arr_out[i] = 0;
							owe = 1;
						}
					}
				}
				
			}
			
			for(var i = 0 ; i <= arr_len; i++) {
				output = output + arr_out[i];
			}
			
			//console.log(output);
			return output;
		}
		
		function isNumber(evt)
		{
			var charCode = (evt.which) ? evt.which : event.keyCode
			if (charCode > 31 && (charCode < 48 || charCode > 57))
				return false;
			return true;
		}
		jQuery(function() {
				jQuery('#datepicker').datepicker( {
					onSelect: function(date) {
						date += " <?php date_default_timezone_set('Asia/Ho_Chi_Minh'); echo gmdate('H:i:s', time()+ 7*3600); ?>";
						jQuery("#datepicker").val(date);
					},
					maxDate: 0,
					//defaultDate: new Date(),
					showOn: "button",
					buttonImageOnly: true,
					changeMonth: true,
					changeYear: true,
					showOn: "button",
					buttonImage: "<?php echo JURI::root();?>administrator/components/com_wrd/assets/images/calendar24x24.png",
					dateFormat: "yy-m-d",
				});
		});
	// ]]> 
</script>

<div style="display: none;" id="element_to_pop_up">
	loading...
</div>
<form action="<?php echo JRoute::_("index.php?option=com_wrd&controller=profile")?>" method="post" name="adminForm" id="adminForm" >
	
	    
	    	<?php 
	   			echo JHtml::_('bootstrap.startTabSet', 'redempt', array('active' => 'detail')); 
	   			echo JHtml::_('bootstrap.addTab', 'redempt', 'detail', 'Details');
	   		?>
			<table class="table">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Guest Name')?>:</label>
					</td>
					<td colspan="2">
						<?php
							if(!empty($this->user_info->f_name) || !empty($this->user_info->l_name)){
								$guest_name = $this->user_info->f_name." ".$this->user_info->l_name ;
							}else{
								$guest_name = $this->data->guest_name ;
							}
						?>
						<input type="text" title="type" maxlength="50" size="50" value="<?php echo $guest_name ; ?>" id="guest_name" name="guest_name" class="guest_name"/> 
					</td>
				</tr>
                
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Category')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['categories']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Create Date')?>:</label>
					</td>
					<td colspan="2">
						<input name="created" type="text" id="datepicker" class="datepicker" value="<?php date_default_timezone_set('Asia/Ho_Chi_Minh'); echo gmdate('Y-m-d H:i:s', time()+ 7*3600); ?>" />
					</td>
				</tr>
				
				<tr style="display: none;">
                    <td class="key">
                        <label for="title"><?php echo JText::_('Product')?>:</label>
                    </td>
                    <td colspan="2">
                        <?php echo $this->lists['products']; ?>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label for="title">Products Quantity:</label>
                    </td>
                    <td colspan="2">
                        <select id="product_quantity">
                            <?php 
                                for($i=1; $i<=100; $i++):
                                    echo '<option value="'.$i.'">'.$i.'</option>';
                                endfor;
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                   
                    <td colspan="4">
                        <table cellpadding="0" cellspacing="0" style="width: 100%;" class="redemption" id="redemption_quantity">
                            <thead>
                                <tr>
                                    <th>Product Name</th>
                                    <th>Quantity</th>
									<th class="v">Code Voucher</th>
									<th class="v">Expired Date</th>
                                    <th>Type Redemption</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
                                    for($i=1; $i<=100; $i++):
                                        echo '
                                            <tr>
                                                <td class="a">
                                                    <select class="product_list" id="product_list'.$i.'" rel="'.$i.'" name="product_name_list[product_list_'.$i.']"></select>
                                                    <a class="view-product-detail">Details</a>
												
                                                </td>
                                                <td style="text-align: center; width:8%;">
                                                    <input class="quantity" id="product_list_'.$i.'" title="Type is number" onkeypress="return isNumber(event)" type="text" value="" name="product_list_'.$i.'" style="width:50px;" />
                                                    <input name="product_list_'.$i.'_hidden" type="hidden" value="" />
                                                </td>
												<td class="v"><div class="v'.$i.'"></div></td>
												<td style="width: 26%;" class="v"><div style="display:none;" class="e'.$i.'"><input name="product_list_'.$i.'_date" type="text" id="datepicker'.$i.'" class="datepicker" rel="'.$i.'" /></div></td>
                                                <td style="padding: 0; width:22%;">
                                                    <div style="width: 96%;background:#e8e8ec;height:20px;padding-top:5px;">
                                                        <input type="radio" checked="checked" value="1" name="product_list_'.$i.'_type" class="point" />&nbsp;
                                                        <div id="p'.$i.'"></div>
                                                    </div>
                                                    <div style="width: 96%;background:#d9decc;">
                                                         <input style="margin-top:7px;" type="radio" value="2" name="product_list_'.$i.'_type" class="point_cash" />&nbsp;
                                                        <div style="width: 100px;" id="pc'.$i.'"></div>
                                                    </div></td>
                                            </tr>        
                                        ';
                                    endfor;
                                ?>
                            </tbody>
                                                        
                        </table>
                    </td>
                </tr>
                
                <tr>
                    <td class="key">
                        <label for="title">Outlet pick up:</label>
                    </td>
                    <td colspan="2">
                        <?php echo $this->lists['filter_pick_up_outlet']; ?>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label for="title">Requested Outlet:</label>
                    </td>
                    <td colspan="2">
                        <?php echo $this->lists['requested_outlet']; ?>
                    </td>
                </tr>			                
                
                <tr>
                    <td class="key">
                        <label for="title">Deliver to outlet Date:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" id="cb-deliver-to-outlet-date" <?php echo ($this->list['filter_deliver_date'] != '' ? 'checked="checked"' : ''); ?> />
                        <div style="display: none;">
                        <?php
                            echo JHTML::_ ( 'calendar', ($this->list['filter_deliver_date'] != '' ? $this->list['filter_deliver_date'] : ''), 'deliver_date', 'deliver_date', '%Y-%m-%d');
                        ?>
                        </div>
                                                
                    </td>
                </tr>
                
                <tr>
                    <td class="key">
                        <label for="title">Pick Up Date:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" id="cb-pick-up-date" <?php echo ($this->list['filter_pick_up_date'] != '' ? 'checked="checked"' : ''); ?> />
                        <div style="display: none;">
                        <?php
                            echo JHTML::_ ( 'calendar', ($this->list['filter_pick_up_date'] != '' ? $this->list['filter_pick_up_date'] : ''), 'pick_up_date', 'pick_up_date', '%Y-%m-%d');
                        ?>
                        </div>
                        <script type="text/javascript">
                            jQuery("#cb-pick-up-date").click(function(){
                                if(jQuery(this).attr("checked") == "checked") {
                                    jQuery(this).next().show();
                                } else {
                                    jQuery(this).next().hide();
                                }
                            });
                            jQuery("#cb-deliver-to-outlet-date").click(function(){
                                
								if(jQuery(this).attr("checked") == "checked") {
                                    jQuery(this).next().show();
                                } else {
                                    jQuery(this).next().hide();
                                }
                            });
                        </script>
                    </td>
                </tr>
                
                <tr>
                    <td colspan="3">
                        &nbsp;
                    </td>
                </tr>
                <tr valign="top">
                    <td class="key">
                        &nbsp;
                    </td>
                    <td colspan="2">
                        <a class="ui-state-default ui-corner-all special-link" id="update_transaction" style="cursor: pointer;"><span class="ui-icon ui-icon-newwin"></span>Update Transaction</a>
                        <a class="ui-state-default ui-corner-all special-link" href="index.php?option=com_wrd&controller=profile&id=<?php echo intval($_GET['id']) ?>&layout=form&tab=redemption" style="cursor: pointer; padding-right: 20px;">Cancel</a>
                         <span style="display: none;" id="loadingImg"><img src="<?php echo JURI::root();?>images/loading.gif" alt="Loading" style="float: none; margin: 0;"> <span>Loading...</span></span>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div id="update_transaction_panel" style="display: none;" class="ui-accordion ui-widget ui-helper-reset ui-accordion-icons">
                            <div>
                                <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-state-active ui-corner-top"><span class="ui-icon ui-icon-triangle-1-s"></span><a href="#" tabindex="-1">Transaction</a></h3>
                                <div id="update_transaction_panel_content" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" style="max-height: 550px;"></div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
        
	<?php 
		echo JHtml::_('bootstrap.endTab');
		if(!empty($this->user_info)):
		echo JHtml::_('bootstrap.addTab', 'redempt', 'infotab', 'User Infomation');
	?>
					<table>
						<tr>
							<td><?php echo JText::_('Member ID') ;?></td>
							<td>:</td>
							<td><strong>
								<?php
									if(!empty($this->user_info->member_id)){
										echo $this->user_info->member_id;
									}
								?> 
								</strong>
								<input type="hidden" name="mid" value="<?php echo $this->user_info->member_id; ?>" />
							</td>
						</tr>
						<tr>
							<td><?php echo JText::_('Name') ;?></td>
							<td>:</td>
							<td><strong>
								<?php
									if(!empty($this->user_info->f_name) || !empty($this->user_info->l_name)){
										$guest_name = $this->user_info->f_name." ".$this->user_info->l_name ;
									}else{
										$guest_name = '' ;
									}
									echo empty($guest_name)? '' : $this->user_info->prefix.' '.$guest_name ; 
								?> 
								</strong>
							</td>
						</tr>
						<tr>
							<td><?php echo JText::_('Mobile') ;?></td>
							<td>:</td>
							<td>
								<?php
									if(!empty($this->user_info->phone)){
										echo $this->user_info->phone;
									}
									else if(!empty($this->user_info->referer_phone)){
										echo $this->user_info->referer_phone;
									}
									else {
										echo "User have not mobiphone";
									}
								?>	
							</td>
						</tr>
						<tr>
							<td><?php echo JText::_('Date of Birth') ;?></td>
							<td>:</td>
							<td>
								<?php
									echo empty($this->user_info->dob)?'':date("d-m-Y",strtotime($this->user_info->dob)) ; 	
								?> 
							</td>
						</tr>
						<?php if(!empty($this->job)): ?>
						<tr>
							<td><?php echo JText::_('Job Title') ;?></td>
							<td>:</td>
							<td>
								<?php  echo empty($this->job) ? '' : $this->job ; ?> 
							</td>
						</tr>
						<?php endif; ?>
						<tr>
							<td><?php echo JText::_('Member Joining Date') ;?></td>
							<td>:</td>
							<td>
								<?php
									echo empty($this->user_info->created_date)?'':date("d-m-Y",strtotime($this->user_info->created_date)) ; 
								?> 
							</td>
						</tr>
						<?php if(!empty($this->outlet->name)): ?>
						<tr>
							<td><?php echo JText::_('Outlet') ;?></td>
							<td>:</td>
							<td>
								<?php
									echo empty($this->outlet->name) ? '' : $this->outlet->name ; 
								?> 
							</td>
						</tr>
						<?php endif; ?>
						<tr>
							<td><?php echo JText::_('Current points balance') ;?></td>
							<td>:</td>
							<td>
							
								<?php  echo number_format($this->p_o_u->point,0,',',','); ?> 
								<input type="hidden" name='p_o_u' id='p_o_u' value='<?php echo $this->p_o_u->point ;?>' />
							</td>
						</tr>
						<tr>
							<td><?php echo JText::_('Total spending') ;?></td>
							<td>:</td>
							<td>
								<?php  echo number_format($this->user_info->total_spend,0,',',','); ?> 
							</td>
						</tr>
					</table>
				<?php 
				echo JHtml::_('bootstrap.endTab');
				?>

	<?php  endif ; ?>
	<div id="stats" style="float:right;margin: 10px 0 ; width:40%">
		<div id='product_info'>&nbsp;</div>
	</div>
	<input type="hidden" name="controller" value="profile" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="uid" value="<?php echo (int)$this->user_info->user_id;?>" />
	<input type="hidden" name="task" value="savenewredemption" />
	<?php echo JHtml::_('bootstrap.endTabSet'); echo JHTML::_( 'form.token' ); ?>
</form>
<input type="hidden" id="current-product-id">
<!-- ui-dialog -->
<div id="dialog" title="Product details">
    <div class="dialog-content">
        
    </div>
</div>